﻿Public Class RELATORIO
    Private Sub RELATORIO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CADASTROTableAdapter.Fill(Me.CADASTRODataSet.CADASTRO)
        Me.ReportViewer1.RefreshReport()
    End Sub
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            Label2.Visible = True
            MaskedTextBox2.Visible = True
        Else
            Label2.Visible = False
            MaskedTextBox2.Visible = False
        End If
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If TextBox1.Text = "" Then
            MsgBox("FAVOR INFORMAR RAZÃO SOCIAL PARA PESQUISA")
        Else
            CADASTROTableAdapter.FillByRAZAO(CADASTRODataSet.CADASTRO, TextBox1.Text)
            Me.ReportViewer1.RefreshReport()
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If TextBox2.Text = "" Then
            MsgBox("FAVOR INFORMAR NOME DO OPERADOR")
        ElseIf TextBox2.Text <> "" And LoginForm1.GRUPOComboBox.Text = "MASTER" Then
            If CheckBox1.Checked = True Then
                CADASTROTableAdapter.FillByOPULT(CADASTRODataSet.CADASTRO, TextBox2.Text, MaskedTextBox1.Text, MaskedTextBox2.Text)
                ReportViewer1.RefreshReport()
            Else
                CADASTROTableAdapter.FillByOPERADOR(CADASTRODataSet.CADASTRO, TextBox2.Text)
                ReportViewer1.RefreshReport()
            End If
        ElseIf TextBox2.Text <> "" And LoginForm1.GRUPOComboBox.Text = "USUARIO" Then
            If CheckBox1.Checked = True And TextBox2.Text = LoginForm1.USUARIOTextBox.Text Then
                CADASTROTableAdapter.FillByOPULT(CADASTRODataSet.CADASTRO, TextBox2.Text, MaskedTextBox1.Text, MaskedTextBox2.Text)
                ReportViewer1.RefreshReport()
            Else
                MsgBox("Cada usuário só pode consultar o seu próprio relatório")
                CADASTROTableAdapter.FillByOPERADOR(CADASTRODataSet.CADASTRO, TextBox2.Text)
                ReportViewer1.RefreshReport()
            End If
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If CheckBox1.Checked = True Then
            If MaskedTextBox1.Text = "  /  /" And MaskedTextBox2.Text = "  /  /" Or MaskedTextBox1.Text = "  /  /" Or MaskedTextBox2.Text = "  /  /" Then
                MsgBox("FAVOR PREENCHER TODOS OS CAMPOS DA PESQUISA")
            Else
                CADASTROTableAdapter.FillByENTREULTCONTA(CADASTRODataSet.CADASTRO, MaskedTextBox1.Text, MaskedTextBox2.Text)
                Me.ReportViewer1.RefreshReport()
            End If
        ElseIf CheckBox1.Checked = False Then
            If MaskedTextBox1.Text = "  /  /" Then
                MsgBox("FAVOR PREENCHER TODOS OS CAMPOS DA PESQUISA")
            Else
                CADASTROTableAdapter.FillByULTCONTATO(CADASTRODataSet.CADASTRO, MaskedTextBox1.Text)
                Me.ReportViewer1.RefreshReport()
            End If
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If CheckBox1.Checked = True Then
            If MaskedTextBox1.Text = "  /  /" And MaskedTextBox2.Text = "  /  /" Or MaskedTextBox1.Text = "  /  /" Or MaskedTextBox2.Text = "  /  /" Then
                MsgBox("FAVOR PREENCHER TODOS OS CAMPOS DA PESQUISA")
            Else
                CADASTROTableAdapter.FillByENTREAGENDA(CADASTRODataSet.CADASTRO, MaskedTextBox1.Text, MaskedTextBox2.Text)
                Me.ReportViewer1.RefreshReport()
            End If
        ElseIf CheckBox1.Checked = False Then
            If MaskedTextBox1.Text = "  /  /" Then
                MsgBox("FAVOR PREENCHER TODOS OS CAMPOS DA PESQUISA")
            Else
                CADASTROTableAdapter.FillByAGENDAMENTO(CADASTRODataSet.CADASTRO, MaskedTextBox1.Text)
                Me.ReportViewer1.RefreshReport()
            End If
        End If
    End Sub
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If CheckBox1.Checked = True Then
            If MaskedTextBox1.Text = "  /  /" And MaskedTextBox2.Text = "  /  /" Or MaskedTextBox1.Text = "  /  /" Or MaskedTextBox2.Text = "  /  /" Then
                MsgBox("FAVOR PREENCHER TODOS OS CAMPOS DA PESQUISA")
            Else
                CADASTROTableAdapter.FillByENTREDATAVISITA(CADASTRODataSet.CADASTRO, MaskedTextBox1.Text, MaskedTextBox2.Text)
                Me.ReportViewer1.RefreshReport()
            End If
        ElseIf CheckBox1.Checked = False Then
            If MaskedTextBox1.Text = "  /  /" Then
                MsgBox("FAVOR PREENCHER TODOS OS CAMPOS DA PESQUISA")
            Else
                CADASTROTableAdapter.FillByDATAVISITA(CADASTRODataSet.CADASTRO, MaskedTextBox1.Text)
                Me.ReportViewer1.RefreshReport()
            End If
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If CheckBox1.Checked = True Then
            If MaskedTextBox1.Text = "  /  /" Or MaskedTextBox2.Text = "  /  /" Then
                MsgBox("FAVOR PREENCHER O PERÍODO", MsgBoxStyle.Information, "Atenção")
            Else
                CADASTROTableAdapter.FillByCOMISSAO(CADASTRODataSet.CADASTRO, MaskedTextBox1.Text, MaskedTextBox2.Text)
                ReportViewer1.RefreshReport()
                Label5.Visible = True
                Label5.Text = ""
                Label5.Text = "Valor comissão:"
                Label5.Text = Label5.Text & " R$ " & (CADASTRODataSet.Tables(0).Rows.Count * 150).ToString
            End If
        Else
            MsgBox("CONSULTA APENAS POR PERÍODO", MsgBoxStyle.Information, "Atenção")
        End If
    End Sub
    Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
        If TextBox2.Text = "" Then
            MsgBox("Favor informar o nome do comercial que gostaria de pesquisar", MsgBoxStyle.Information, "Atenção")
        Else
            Try
                CADASTROTableAdapter.FillByCOMERCIAL(CADASTRODataSet.CADASTRO, TextBox2.Text)
                Me.ReportViewer1.RefreshReport()
            Catch ex As Exception
                MsgBox("Erro ao pesquisar " + Environment.NewLine + ex.ToString, MsgBoxStyle.Information, "Atenção")
            End Try
        End If
    End Sub

    Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
        If CheckBox1.Checked = False Then
            MsgBox("Favor marcar a consulta por período", MsgBoxStyle.Information, "Atenção")
        Else
            If MaskedTextBox1.Text = "" Or MaskedTextBox2.Text = "" Or TextBox2.Text = "" Then
                MsgBox("Favor verificar se foi preenchido o período da data e o nome do comercial", MsgBoxStyle.Information, "Atenção")
            Else
                Try
                    CADASTROTableAdapter.FillByVISITACOMERCIAL(CADASTRODataSet.CADASTRO, MaskedTextBox1.Text, MaskedTextBox2.Text, TextBox2.Text)
                    Me.ReportViewer1.RefreshReport()
                Catch ex As Exception
                    MsgBox("Erro ao pesquisar " + Environment.NewLine + ex.ToString, MsgBoxStyle.Information, "Atenção")
                End Try
            End If
        End If
    End Sub
End Class